<?php
include('../../include/functions.inc.php');
$list = $db->query_select("cllg_career", "FK_ENTITY=" . $user->entity);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Asignacion de Estudiantes</title>
        <link href="../../bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <link href="../../css/ContentStyle.css" rel="stylesheet" type="text/css" />
        <link href="../../js/protocalendar/datepicker.css" rel="stylesheet" type="text/css" />
        <link href="../../css/tableorderer.css" rel="stylesheet" type="text/css" />
        <link href="../../js/dialog/dialog.2.0.css" rel="stylesheet" type="text/css" />
        <script src="../../js/jquery.js" type="text/javascript"></script>
        <script>jQuery.noConflict();</script>
        <script src="../../bootstrap/js/bootstrap.js"></script>
        <script src="../../js/prototype.js" type="text/javascript"></script>
        <script src="../../js/jsvalidate.js" type="text/javascript"></script>
        <script src="../../js/TableOrderer.js" type="text/javascript"></script>
        <script src="../../js/dialog/dialog.2.0.js" type="text/javascript"></script>
        <script src="../../js/include.js" type="text/javascript"></script>
        
        <script type="text/javascript">
            var cargos=null;

            showStudents=function(){
                var f=new Hash({tittle:'Listado de Catedraticos',url:'../students/slistStudents.php',callback:selStud,width:500,height:500});
                setList(null,f.toObject());
            }

            showCursos=function(){
                var f=new Hash({tittle:'Listado de Cursos',url:'../courses/list.php',callback:selCourse,width:500,height:500});
                setList(null,f.toObject());
            }

            selStud=function(s){
                $("ID").value=s.CARNET;
                $("NAME").value=s.NOMBRE_A+' '+s.NOMBRE_B+' '+s.APELLIDOS;	
                showAssigns($F("ID"));
            }

            selCourse=function(s){
                $("CODE").value=s.CODIGO;
                $("NCURSO").value=s.NOMBRE;	
                Dialogs.close();
            }
            hideAdd=function(){
                $(document.ADD).reset();
                $("suelto").hide();
            }

            showAssigns=function(idStud){
                waitMsg("Cargando asignaciones...");
                var pars="operation=assigns&ID="+idStud;
                new Ajax.Updater("asignaciones","data.php",
                {parameters:pars,
                    method:"get",
                    onComplete:function(r){
                        closeWait();
                    }});
            }

            showCourses=function(idAssign){
                $("ID_ASSIGN").value=idAssign;
                waitMsg("Cargando cursos...");
                var pars="operation=detail&ID="+idAssign;
                new Ajax.Updater("cursos","data.php",
                {parameters:pars,method:"get",
                    onComplete:function(r){
                        //alert(r.responseText);
                        closeWait();
                    }});
            }
            cancelAssign=function(idAssign){
                Dialogs.confirm("Esta seguro de anular la asignacion?",
                function(){  
                    waitMsg("Guardando...");
                    var pars="operation=cancel&ID="+idAssign;
                    new Ajax.Request("data.php",{parameters:pars,method:'get',
                        onComplete:function(r){
                            // alert(r.responseText);
								 
                            closeWait();
                            showAssigns($F("ID"));
                            jQuery("#cursos").html("");
                        }});
                },
                function(){Dialogs.alert("Operacion Cancelada");});
            }
            deleteAssign=function(idAssign){
                Dialogs.confirm("Esta seguro de eliminar la asignacion?",
                function(){  
                    waitMsg("Guardando...");
                    var pars="operation=delete&ID="+idAssign;
                    new Ajax.Request("data.php",{parameters:pars,method:'get',
                        onComplete:function(r){
                            // alert(r.responseText);
								 
                            closeWait();
                            showAssigns($F("ID"));
                            jQuery("#cursos").html("");
                        }});
                },
                function(){Dialogs.alert("Operacion Cancelada");});
            }
            
            cancelCourse=function(idCourse){
                Dialogs.confirm("Esta seguro de quitar el curso de la asignacion?",
                function(){  
                    Dialogs.close();
                    waitMsg("Anulando...");
                    var pars="operation=cancelcourse&ID_DET_ASSIGN="+idCourse;
                    new Ajax.Request("data.php",{parameters:pars,method:'get',
                        onComplete:function(r){
                            showCourses($F("ID_ASSIGN"));
                            closeWait();
                        }});
                },
                function(){Dialogs.alert("Operacion Cancelada");});
            }
            
            deleteCourse=function(idCourse){
                Dialogs.confirm("Esta seguro de eliminar el curso de la asignacion?",
                function(){  
                    Dialogs.close();
                    waitMsg("Eliminando...");
                    var pars="operation=deletecourse&ID_DET_ASSIGN="+idCourse;
                    new Ajax.Request("data.php",{parameters:pars,method:'get',
                        onComplete:function(r){
                            showCourses($F("ID_ASSIGN"));
                            closeWait();
                        }});
                },
                function(){Dialogs.alert("Operacion Cancelada");});
            }
            addOnLoad(hideAdd);

            var rsv;
            config=function(){ 
                rsv=new RSV({
                    formID: $(document.ADD),
                    errorFieldClass: "errorField",
                    rules: ["required,ID_ASSIGN,Selecciones una Asignacion!",
                        "required,CODE,Seleccione un Curso!",
                        "required,SECTION,Seleccione un aseccion!"],
                    displayType : "display-html",
                    errorHTMLItemBullet : "&#8212; ",
                    onCompleteHandler:function(){
                        waitMsg("Guardando...");
                        $('operation').value='add';
                        $(document.ADD).request({onComplete:function(r){
                                if(r.responseJSON.ST==1){
                                    Dialogs.alert(r.responseJSON.MSG);
                                    showCourses($F("ID_ASSIGN"));
                                    $(document.ADD).reset();
                                }else{
                                    alert(r.responseJSON.ERROR);
                                }
                                closeWait();
                            }});
							
                    }});
            }

            addOnLoad(config);



        </script>
    </head>

    <body>
        <div id="tabs">
            <ul class="nav nav-tabs">
                <li class="active">
                    <a>Reasignaciones de estudiantes</a>
                </li>
            </ul>
        </div>
        <div id="rsvErrors"></div>
        <div id="tab-cont">
            <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th colspan="2" scope="col">

                    </th>
                </tr>
                <tr>
                    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="20%">NO. CARNET</td>
                                <td width="80%"><input name="ID" type="text" readonly="readonly" id="ID" />
                                    <input name="buscar" onclick="showStudents()" type="button" class="btn btn-small" id="buscar"  value=".." /></td>
                            </tr>
                            <tr>
                                <td>NOMBRE </td>
                                <td><input name="NAME" type="text" id="NAME" readonly="readonly" size="50" /></td>
                            </tr>
                        </table></td>
                </tr>
                <tr>

                    <th colspan="2" scope="col"><br/><legend>Asignaciones Vigentes</legend></th>
                </tr>
                <tr>
                    <td colspan="2" id="asignaciones">&nbsp;</td>
                </tr>
            </table>
            <div id="suelto">
                <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <th width="54%" scope="col" style="text-align: right"><legend>Nuevo Curso</legend></th>
                        <th width="46%" scope="col"><legend><div class="btn-group"><input type="button" name="cmdadd" id="cmdadd"  class="btn btn-info" value="Continuar" onclick="rsv.validate();" />
                            <input type="button" name="cmddek" id="cmddek"  class="btn btn-info" value="Cancelar" onclick="rsv.validate();" /></div></legend></th>
                    </tr>
                    <tr>
                        <td colspan="2"><form id="ADD" name="ADD" method="get" action="data.php">
                                <table width="100%" border="0" cellspacing="0">
                                    <tr>
                                        <td width="25%">Codigo</td>
                                        <td width="75%"><input name="CODE" type="text" readonly="readonly" id="CODE" />
                                            <input name="buscar2" onclick="showCursos()" type="button" class="btn btn-small" id="buscar2"  value="..." />
                                            <input type="hidden" name="ID_ASSIGN" id="ID_ASSIGN" />
                                            <input type="hidden" name="operation" id="operation" /></td>
                                    </tr>
                                    <tr>
                                        <td>Nombre</td>
                                        <td><input name="NCURSO" type="text" id="NCURSO" readonly="readonly" size="50" /></td>
                                    </tr>
                                    <tr>
                                        <td>Seccion</td>
                                        <td><select name="SECTION" id="SECTION">
                                                <option value="A" selected="selected">A</option>
                                                <option value="B">B</option>
                                                <option value="C">C</option>
                                                <option value="D">D</option>
                                                <option value="E">E</option>
                                                <option value="F">F</option>
                                                <option value="G">G</option>
                                                <option value="H">H</option>
                                                <option value="I">I</option>
                                                <option value="J">J</option>
                                                <option value="K">K</option>
                                                <option value="L">L</option>
                                                <option value="M">M</option>
                                                <option value="N">N</option>
                                                <option value="O">O</option>
                                            </select>            </td>
                                    </tr>
                                </table>
                            </form>      </td>
                    </tr>
                </table>
            </div>
            <div id="fijo">
                <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <th width="58%" scope="col" style="text-align: right"><legend>Cursos de Asignacion</legend></th>
                        <th width="42%" scope="col" style="padding-top: 0.8%"><legend><input type="button" name="cmdadd" id="cmdadd" class="btn btn-info" onclick="$('suelto').show();" value="Agregar"/></legend></th>
                    </tr>
                    <tr>
                        <td colspan="2" id="cursos">&nbsp;</td>
                    </tr>
                </table>
            </div>
        </div>   
    </body>
</html>
